Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Update of Windows vm and vmss with non-empty additional_unattend_config.content #377

Conversation

dominik-lekse
Copy link
Contributor

@dominik-lekse dominik-lekse commented Sep 30, 2017

This pull request fixes a crash when updating a azurerm_virtual_machine or azurerm_virtual_machine_scale_set resource which has been previously created with a value set for content in the additional_unattend_config.

Terraform Version

v0.10.5

Terraform AzureRM Provider Version

0.2.2

Affected Resources

  • azurerm_virtual_machine
  • azurerm_virtual_machine_scale_set

Steps to reproduce

  1. Create Windows virtual machine using azurerm_virtual_machine with a non-empty field content in the additional_unattend_config block such as
additional_unattend_config {
    pass = "oobeSystem"
    component = "Microsoft-Windows-Shell-Setup"
    setting_name = "AutoLogon"
    content = "<AutoLogon><Username>Operations</Username><Password><Value>dRaQuDH7vWZLWFf6</Value></Password><Enabled>true</Enabled><LogonCount>1</LogonCount></AutoLogon>"
  • Run terraform apply
  • Change any parameter of the Windows VM resource in the Terraform configuration, e.g. the vm_size
  • Run terraform apply

Expected Behavior

  • After the second terraform apply, the resource should be changed accordingly, e.g. a resize should have been performed

Actual Behavior

  • Terraform crashed with the following error message
* azurerm_virtual_machine.test: compute.VirtualMachinesClient#CreateOrUpdate: Failure responding to request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=409 Code="PropertyChangeNotAllowed" Message="Changing property 'windowsConfiguration.additionalUnattendContent.content' is not allowed."

Cause analysis

  • After creating a virtual machine resource, the content field will be returned as nil by the Azure Go SDK
  • Therefore the field is saved as an empty string in the state
  • The field must not be send to to Azure API as "" but rather as nil (or not in the request)
  • Currently the Azure API assumes the field should be changed to an empty string "" which is not allowed

Steps to reproduce via tests

azurerm_virtual_machine

This pull request includes a new test TestAccAzureRMVirtualMachine_windowsMachineResize which resizes a Windows virtual machine with additionalUnattendContent.content set.

Without the changes, the test fails:

make testacc TEST=./azurerm TESTARGS='-run=TestAccAzureRMVirtualMachine_windowsMachineResize'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./azurerm -v -run=TestAccAzureRMVirtualMachine_windowsMachineResize -timeout 120m
=== RUN   TestAccAzureRMVirtualMachine_windowsMachineResize
--- FAIL: TestAccAzureRMVirtualMachine_windowsMachineResize (462.73s)
	testing.go:434: Step 1 error: Error applying: 1 error(s) occurred:

		* azurerm_virtual_machine.test: 1 error(s) occurred:

		* azurerm_virtual_machine.test: compute.VirtualMachinesClient#CreateOrUpdate: Failure responding to request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=409 Code="PropertyChangeNotAllowed" Message="Changing property 'windowsConfiguration.additionalUnattendContent.content' is not allowed."
FAIL
exit status 1
FAIL	github.com/terraform-providers/terraform-provider-azurerm/azurerm	462.756s
make: *** [testacc] Error 1

With the changes, the test passes:

make testacc TEST=./azurerm TESTARGS='-run=TestAccAzureRMVirtualMachine_windowsMachineResize'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./azurerm -v -run=TestAccAzureRMVirtualMachine_windowsMachineResize -timeout 120m
=== RUN   TestAccAzureRMVirtualMachine_windowsMachineResize
--- PASS: TestAccAzureRMVirtualMachine_windowsMachineResize (603.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	603.036s

azurerm_virtual_machine_scale_set

This pull request includes a new test TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize which resizes a Windows virtual machine scale set with additionalUnattendContent.content set.

Without the changes, the test fails:

make testacc TEST=./azurerm TESTARGS='-run=TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./azurerm -v -run=TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize -timeout 120m
=== RUN   TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize
--- FAIL: TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize (514.91s)
	testing.go:434: Step 1 error: Error applying: 1 error(s) occurred:

		* azurerm_virtual_machine_scale_set.test: 1 error(s) occurred:

		* azurerm_virtual_machine_scale_set.test: compute.VirtualMachineScaleSetsClient#CreateOrUpdate: Failure responding to request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=409 Code="PropertyChangeNotAllowed" Message="Changing property 'windowsConfiguration.additionalUnattendContent.content' is not allowed."
FAIL
exit status 1
FAIL	github.com/terraform-providers/terraform-provider-azurerm/azurerm	514.938s
make: *** [testacc] Error 1

With the changes, the test passes:

make testacc TEST=./azurerm TESTARGS='-run=TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./azurerm -v -run=TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize -timeout 120m
=== RUN   TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize
--- PASS: TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize (572.55s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	572.578s

@dominik-lekse dominik-lekse changed the title Bugfix/additional unattend config empty content Bugfix: Update of Windows vm and vmss with non-empty additional_unattend_config.content Sep 30, 2017
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dominik-lekse

Thanks for this PR - I've taken a look and this LGTM :)

Thanks!

@tombuildsstuff
Copy link
Contributor

Tests pass:

$ acctests azurerm TestAccAzureRMVirtualMachine_windowsMachineResize
=== RUN   TestAccAzureRMVirtualMachine_windowsMachineResize
--- PASS: TestAccAzureRMVirtualMachine_windowsMachineResize (675.31s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	675.331s
$ acctests azurerm TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize
=== RUN   TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize
--- PASS: TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize (459.46s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	459.490s

@tombuildsstuff tombuildsstuff merged commit e1f7501 into hashicorp:master Oct 2, 2017
tombuildsstuff added a commit that referenced this pull request Oct 2, 2017
@ghost
Copy link

ghost commented Apr 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants